package com.alibaba.cloud.cargo.infrastructure.event.comsumer;

import com.alibaba.cloud.cargo.application.command.CargoCmdService;
import com.alibaba.cloud.cargo.domain.aggregate.cargo.Cargo;
import com.alibaba.cloud.cargo.domain.aggregate.cargo.CargoBookDomainEvent;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author cruise
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class CargoListener {
    private final CargoCmdService cargoCmdService;
    private final EventBus eventBus;

    @PostConstruct
    public void init() {
        eventBus.register(this);
    }

    @Subscribe
    public void recordCargoBook(CargoBookDomainEvent event) {
        // invoke application service or domain service
        final Cargo cargo = event.getCargo();
        log.info("CargoListener: recordCargoBook......,{}", cargo);
    }
}
